const { MOCK } = require('../utils').settings
const axios = require('../utils/axios')
const { error } = require('../utils/error')
const {
  mockAllClass,
  mockUserClass,
  mockEditUserClass
} = require('./mock/classification')
const apiError = (msg) => {
  error('50000', __dirname, msg)
}
// class - allClass
exports.requestAllClass = async () => {
  let result = MOCK ? mockAllClass : await axios.get('/getPlateAndClass')
  if (!result) {
    apiError('requestAllClass')
    result = mockAllClass
  }
  return result
}
// class - userClass
exports.requestUserClass = async (data = {}) => {
  let result = MOCK
    ? mockUserClass
    : await axios.get('/user/getFollowPlate', {
        params: data
      })
  if (!result) {
    apiError('requestUserClass')
    result = mockUserClass
  }
  return result
}
// class - editUserClass
exports.requestEditUserClass = async (data = {}) => {
  let result = MOCK
    ? mockEditUserClass
    : await axios.post('/user/editFollowPlate', data)
  if (!result) {
    apiError('requestEditUserClass')
    result = mockEditUserClass
  }
  return result
}
